home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr22 / dtkclk11.zip / CLKDEFS.H < prev    next >
Text File  |  1993-05-05  |  4KB  |  116 lines

  1. /*
  2.  * Program to handle a DTK clock/calendar board based on the OKI 5832 chip.
  3.  *
  4.  *    (C) Copyright 1989 Richard B. Wales.
  5.  *    All Rights Reserved.  This program may be freely copied and
  6.  *    distributed for commercial or non-commercial use, provided:
  7.  *    (1) this source code is included in any distribution;
  8.  *    (2) all copyright notices are retained intact; and
  9.  *    (3) no charge (other than a reasonable copying or communications
  10.  *        charge) is assessed.
  11.  */
  12.  
  13. #include <dos.h>
  14.  
  15. /*
  16.  * 8255 (PPI) I/O port addresses.
  17.  * The "base" address is determined by the DTK circuit board layout,
  18.  * as is the allocation of the PPI's three data ports (A, B, and C)
  19.  * to the various functions on the 5832 clock/calendar chip.
  20.  */
  21. #define CLKBASE 0x020c
  22. #define CLKDATA (CLKBASE+0)        /* PPI port A (clock data) */
  23. #define CLKADDR (CLKBASE+1)        /* PPI port B (clock address) */
  24. #define CLKCTRL (CLKBASE+2)        /* PPI port C (clock control) */
  25. #define PPICTRL (CLKBASE+3)        /* PPI control port */
  26.  
  27. /*
  28.  * Values for PPICTRL.
  29.  * These values control the read/write status of the PPI's data ports.
  30.  * Consult the 8255 technical specs for more info.
  31.  */
  32. #define PPI_READ    0x90        /* read port A; write B and C */
  33. #define PPI_WRITE    0x80        /* write ports A, B, and C */
  34.  
  35. /*
  36.  * Values for CLKCTRL (to signal lines on 5832 chip).
  37.  * The allocation of the bits of PPI port C to the 5832's signal lines
  38.  * is determined by the DTK circuit board layout.
  39.  */
  40. #define CLK_SELECT    0x80        /* clock chip select */
  41. #define CLK_HOLD    0x40        /* hold clock value for I/O */
  42. #define CLK_READ    0x20        /* read from clock */
  43. #define CLK_WRITE    0x10        /* write to clock */
  44.  
  45. /*
  46.  * Macros for reading from the clock.
  47.  */
  48. #define READY_TO_READ    { outportb (CLKCTRL, CLK_SELECT + CLK_READ); }
  49. #define READ_CLOCK(x)    { outportb (CLKADDR, x); \
  50.               CLK_READ_DELAY; \
  51.               clkdata[x] = inportb (CLKDATA) & 0xf; \
  52.             }
  53. #define DONE_READING    { outportb (CLKCTRL, 0); }
  54.  
  55. /*
  56.  * Macros for writing to the clock.
  57.  */
  58. #define READY_TO_WRITE    { outportb (CLKCTRL, CLK_SELECT+CLK_HOLD); \
  59.               CLK_HOLD_DELAY; \
  60.             }
  61. #define WRITE_CLOCK(x)    { outportb (CLKADDR, x); \
  62.               outportb (CLKDATA, clkdata[x]); \
  63.               CLK_WRITE_DELAY; \
  64.               outportb (CLKCTRL, CLK_SELECT+CLK_HOLD+CLK_WRITE); \
  65.               CLK_WRITE_DELAY; \
  66.               outportb (CLKCTRL, CLK_SELECT+CLK_HOLD); \
  67.             }
  68. #define DONE_WRITING    { outportb (CLKCTRL, 0); }
  69.  
  70. /*
  71.  * Time delay loops.
  72.  * Required delays as specified in the OKI MSM5832RS documentation:
  73.  *         Hold setup  (tHS):  150 usec
  74.  *         Read access (tRA):    6 usec
  75.  *         Write pulse (tWW):    1 usec
  76.  */
  77. #define CLK_HOLD_DELAY    { int x; for (x = 250; x > 0; x--) ; }
  78. #define CLK_READ_DELAY    { int x; for (x = 10; x > 0; x--) ; }
  79. #define CLK_WRITE_DELAY    { int x; for (x = 2; x > 0; x--) ; }
  80.  
  81. /*
  82.  * Data structure for clock values.
  83.  * All values are in two-digit BCD form.
  84.  */
  85. struct clockval
  86. {    unsigned char cv_century,
  87.               cv_year,
  88.               cv_month,
  89.               cv_day,
  90.               cv_hour,
  91.               cv_minute,
  92.               cv_second;
  93. };
  94. #define NULL_CLOCK    (struct clockval *) 0
  95. #define NULL_DATE    (struct date *) 0
  96. #define NULL_TIME    (struct time *) 0
  97. #define NULL_CLOCK_P    (struct clockval **) 0
  98. #define NULL_DATE_P    (struct date **) 0
  99. #define NULL_TIME_P    (struct time **) 0
  100.  
  101. /* in READ.C */
  102. struct clockval    *read_clock     (void);
  103. void         clock_to_time     (struct clockval *cv,
  104.                   struct date **da,
  105.                   struct time **ti);
  106.  
  107. /* in WRITE.C */
  108. struct clockval *write_clock     (struct clockval *cv);
  109. void         time_to_clock     (struct date *da,
  110.                   struct time *ti,
  111.                   struct clockval **cv);
  112.  
  113. /* in CAL.C */
  114. void         advance_time     (struct clockval *cv,
  115.                   int seconds);
  116. int         day_of_the_week (struct clockval *cv);